﻿using System;
using Tao.OpenGl;

namespace Aeon.Framework.Objects
{

/// <summary>
/// Portable screen text object class.
/// Selectable font, size and color.
/// Renders on unscaled orthogonal.
/// 
/// </summary>
public class Text : IKey, IMove, IDraw
    {
    // --- Fields & Accessors:

    private String id;          public String ID       { get { return(id);     } }
    private Position origin;    public Position Origin { get { return(origin); } }
    
    private String text;            // Font text.
    private IFont face;             // Font texture.
    
    public FontType Style { get { return(face.Style); } }
    public String Write { get { return(text); } set { text = value; } } // [TODO] Not cool. Bypassing World like that.
    
    // --- Constructor:

    public Text(String key, Position pos, IFont font, String text)
        {
        id = key;
        face = font;
        origin = pos;

        this.text = text;
        }

    // --- Interface Methods:

    public void Draw()
        {
        face.Render();
        
        Gl.glMatrixMode(Gl.GL_PROJECTION);
        Gl.glPushMatrix();
        Gl.glLoadIdentity();

        Gl.glMatrixMode(Gl.GL_MODELVIEW);
        Gl.glPushMatrix();
        Gl.glLoadIdentity();

        Gl.glTranslatef(origin.xPos,Origin.yPos,Origin.zPos);
        Gl.glColor4f(face.Style.Color.R,face.Style.Color.G,face.Style.Color.B,face.Style.Color.A);
        Gl.glScalef(0.005f, 0.005f, 0.005f);
        
        face.BeginFont();
        face.Write(text);
        face.EndFont();

        Gl.glPopMatrix();
        Gl.glMatrixMode(Gl.GL_PROJECTION);

        Gl.glPopMatrix();
        Gl.glMatrixMode(Gl.GL_MODELVIEW);
        }

    public void MoveTo(Position pos) { origin.Change(pos);    }
    public void MoveBy(IVector vec)   { origin.Transform(vec); }
    }
    

}